#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 310

int f[N][N];

int s[N];

int main()

{

    int n;

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)

    {

        int x;

        scanf("%d", &x);

        s[i] = x + s[i - 1];

    }

    for (int i = 2; i <= n; i++)

    {

        for (int j = 1; j + i - 1 <= n; j++)

        {

            int l = j, r = j + i - 1;

            f[l][r] = 0x3f3f3f3f;

            for (int k = l; k < r; k++)

            {

                f[l][r] = fmin(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]);

            }

        }

    }

    printf("%d\n", f[1][n]);

    return 0;

}